
var pageContext = new PageContext(settings||{});

pageContext.formInit = function(layero){
	
} 
pageContext.init = function(){//初始化
	pageContext.initEvent();
};
pageContext.updateItemAfter = function(result,para){
	 window.location =  window.global.getFinalUrl(window.global.ctx+'/info/company/index?_json=0'); 
};
pageContext.addItemAfter = function(result,para){
	 window.location =  window.global.getFinalUrl(window.global.ctx+'/info/company/index?_json=0'); 
};
pageContext.save = function(){
	var form = $("#"+pageContext.setting.formId);
	 var para = form.formSerializeNotBlank(); 
	 if(form.validationEngine("validate")){
		 var option = {
			 url:window.global.ctx+"/info/company/save",
			 msg:"确定保存？",
			 failMsg:"保存失败", 
			 successMsg:"保存成功",
			 success:function(result){
				 window.location =  window.global.getFinalUrl(window.global.ctx+'/info/company/index?_json=0'); 
			 }
		 };
		 pageContext.saveItem(para,option); 
	 }
}
jQuery(function($) {
	$('#homeAddress').citys({
	dataUrl:window.global.ctx+"/static/fw/plugin/data_location/list.json?noPage=1"
	 ,code:$("#editForm").find("select[name='a.provinceCode']").attr("value")
	 ,province:$("#editForm").find("select[name='a.provinceCode']").attr("value")             
     ,city:$("#editForm").find("select[name='a.cityCode']").attr("value")         
     ,area:$("#editForm").find("select[name='a.districtCode']").attr("value")
	 ,provinceField:'a.provinceCode' //省份字段名
     ,cityField:'a.cityCode'         //城市字段名
     ,areaField:'a.districtCode'         //地区字段名
	 ,required:false
	,onChange:function(me,info){
		if(me!=null){
		var p = $(me).attr("prefix");
		   if(p && p!=""){
			   var val = $(me).find("option:selected").val();
			   var text = "";
			   if(val!=""){
				   text = $(me).find("option:selected").text();
			   }
			   $('#editForm input[name="'+p+'Name"]').val(text).change();
		   }
		}
	},onReady:function(){
	}});
	$(".home").on("change",function(){
		var map = new Map();
		$(".home").each(function(){
			map.put($(this).attr("index"),$(this).val());
		});
		var index = 1;
		var $input = $('#editForm input[name="a.address"]');
		var str = "";
		while(index<=4){
			var v = map.get(index);
			if(v!=null && v!=undefined){
				str+=v;
			}
			index++;
		}
		$input.val(str);
	});
	$("#editForm .inputElem").mailAutoComplete({height:"100px"});
   pageContext.init({});
   $('#editForm select[novalid!="true"]').on("change",function(){
	   var me = this;
	    var p = $(this).attr("prefix");
	   if(p && p!=""){
		   var val = $(me).find("option:selected").val();
		   var text = "";
		   if(val!=""){
			   text = $(me).find("option:selected").text();
		   }
		   $('#editForm input[name="'+p+'Name"]').val(text).change();
	   }
   })
	if(!ace.vars['touch']) {
		$('#editForm select[novalid!="true"]').on('chosen:showing_dropdown', function(e, params) {
			pageInit();
		});
		$('#editForm select[novalid!="true"]').on('chosen:ready', function(e, params) {
			params.chosen.search_results.css("maxHeight","100px");
		});
		var d= $('#editForm select[novalid!="true"]').chosen({allow_single_deselect:true,
		    disable_search_threshold: 5,max_selected_options:2}); 
		//resize the chosen on window resize
		$(window)
		.off('resize.chosen')
		.on('resize.chosen', function() {
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			})
		}).trigger('resize.chosen');
		//resize chosen on sidebar collapse/expand
		$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
			if(event_name != 'sidebar_collapsed') return;
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			})
		});
	}
   $('#editForm select').change();
   $('#desc').inputlimiter({
		remText: '剩余%n个字符...',
		limitText: '最大允许字符: %n.'
	});
	$('textarea[class*=autosize]').autosize({append: "\n"});
	var form =  $("#"+pageContext.setting.formId);
	form.validationEngine('attach', {promptPosition : "topLeft", autoPositionUpdate : true});
	pageInit();
}); 
